<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言板</title>
</head>
<body>
    <div id="app">
        <div>
            <div>
                <label for="author">发布者：</label>
                <input type="text" v-model="author" id="author">
            </div>
            <div>
                <label for="centent">发布内容：</label>
                <input type="text" v-model="centent" id="centent">
            </div>
            <button @click='publish'>留言</button>
            
        </div>
        <cpn :list='msgs'></cpn> 
    </div>

    <template id="cpns">
        <div>
            <ul>
                <li v-for='item in list' :key='item.id'>
                    <p><span>留言人：</span>{{item.author}}</p>
                    <p><span>留言内容：</span>{{item.centent}}</p>
                </li>
            </ul>
        </div>
    </template>
</body>
<script src='../js/vue.js'></script>
<script>
    Vue.component('cpn', {
        template:'#cpns',
        props:{
            list:{
                type:Array,
            }
        }
    })

    let app = new Vue({
        el: '#app',
        data: {
             msg:'hello vue.js',
             author:'',
             centent:'',
             msgs:[
                 {id:1,author:'张三',centent:'hello'}
             ]
        },
        methods: {
            publish(){
                this.msgs.unshift({
                    id:this.msgs.length+1,
                    author:this.author,
                    centent:this.centent
                })
            }
        }
    })
</script>
</html>